package com.pj.wisdomlogistics.ui.adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.pj.wisdomlogistics.R;
import com.pj.wisdomlogistics.cons.Cons;
import com.pj.wisdomlogistics.entity.TransactHistoryInfo;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseAdapter;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseViewHolder;
import com.zhy.autolayout.utils.AutoUtils;

public class TransactHistoryAdapter extends BaseAdapter<TransactHistoryInfo.ListBean, BaseViewHolder> {
    public TransactHistoryAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder createCustomViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(parent, R.layout.item_my_apply);
    }

    @Override
    public void bindCustomViewHolder(BaseViewHolder viewHolder, int position) {
        AutoUtils.autoSize(viewHolder.itemView);

        final TransactHistoryInfo.ListBean item = getItem(position);

        TextView mTv1 = viewHolder.getTextView(R.id.tv_apply_1);
        TextView mTv2 = viewHolder.getTextView(R.id.tv_apply_2);
        TextView mTv3 = viewHolder.getTextView(R.id.tv_apply_3);
        TextView mTv4 = viewHolder.getTextView(R.id.tv_apply_4);

        ImageView mIvBg = viewHolder.getView(R.id.iv_bg);
        mTv3.setVisibility(View.GONE);

        switch (Integer.parseInt(item.getTag())) {
            case Cons.ApplyType.APPLY_GWYC:
                mTv1.setText("用车申请");
                mIvBg.setBackgroundResource(
                        (item.getState() ==  8 || item.getState() == 9 || item.getState() == 10)? R.drawable.yongche2:
                                (item.getState() == 5 || item.getState() == 6) ? R.drawable.yongche3 : R.drawable.yongche);
                mTv2.setText(context.getResources().getString(R.string.apply_time) + ":" + item.getParam1());
                mTv4.setText(context.getResources().getString(R.string.apply_state) + ":" + Cons.carYetList.get(item.getState()));
                break;
            case Cons.ApplyType.APPLY_HYS:
                mTv1.setText("会议室申请");
                mTv2.setText(context.getResources().getString(R.string.apply_time) + ":" + item.getParam1());

                if(item.getCancel() == 1){
                    mIvBg.setBackgroundResource(R.drawable.huiyishi2);
                    mTv4.setText(context.getResources().getString(R.string.apply_state) + ":" + "已撤销");
                }else{
                    mIvBg.setBackgroundResource(
                            (item.getState() == 9 || item.getState() == 10)?R.drawable.huiyishi2:
                                    item.getState() == 5 ? R.drawable.huiyishi3 :R.drawable.huiyishi);
                    mTv4.setText(context.getResources().getString(R.string.apply_state) + ":" + Cons.statusYetList.get(item.getState()));
                }
                break;
            case Cons.ApplyType.APPLY_ST:
                mTv1.setText("用餐申请");
                mTv2.setText(context.getResources().getString(R.string.apply_time) + ":" + item.getParam1());

                mIvBg.setBackgroundResource(
                        (item.getState() == 7 || item.getState() ==  8 || item.getState() == 9 || item.getState() == 10)?R.drawable.shitang2:
                                (item.getState() == 6 || item.getState() == 5) ? R.drawable.shitang3 : R.drawable.shitang);
                mTv4.setText(context.getResources().getString(R.string.apply_state) + ":" + Cons.canteenYetList.get(item.getState()));
                break;
            case Cons.ApplyType.APPLY_WHBX:
                mTv1.setText("维护报修");
                mIvBg.setBackgroundResource(
                        (item.getState() == 0 || item.getState() == 1)? R.drawable.weihu : R.drawable.weihu3);
                mTv2.setText(context.getResources().getString(R.string.repair_time) + ":" + item.getParam1());
                mTv4.setText(context.getResources().getString(R.string.apply_state) + ":" + Cons.repairList.get(item.getState()));
                break;
            case Cons.ApplyType.APPLY_WMDC:
                mTv1.setText("外卖点餐");
                mTv2.setText(context.getResources().getString(R.string.order_time) + ":" + item.getParam1());
                mIvBg.setBackgroundResource(
                        item.getState() == 0 ? R.drawable.waimai : item.getState() == 1 ? R.drawable.waimai3 : R.drawable.waimai2);
                mTv1.setText(item.getOrderType() == 0 ? item.getTitle() + "(熟食)" : item.getTitle() + "(面食)");
                mTv4.setText(context.getResources().getString(R.string.order_state) + ":" + Cons.takeoutList.get(item.getState()));
                break;
        }

        mIvBg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClick.itemClick(Integer.parseInt(item.getTag()) , item.getId());
            }
        });

    }

    @Override
    public int getCustomViewType(int position) {
        return 0;
    }


    public onItemClick mOnItemClick;

    public interface onItemClick{
        public void itemClick(int type, int id);
    }

    public void setListener(onItemClick mListener){
        this.mOnItemClick = mListener;
    }

}
